/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formatconversion_model;

import magic_toolbox.Magic_ToolboxView;
import org.jdesktop.beansbinding.Converter;

/**
 * 
 * @author Tobias
 */
public class InputToOutputFileNameConverter extends Converter{
    //private FileType fileType= FileType.none;
    private Magic_ToolboxView mv;
    
    public InputToOutputFileNameConverter(Magic_ToolboxView mv) {
        this.mv = mv;
    }
    
    /*
        public void setFileType(FileType fileType){
            this.fileType = fileType;
        }
    */
    
    @Override
    public Object convertForward(Object value) {
       String filename = (String) value;
       if(!filename.contains("."))return filename;
       String name = filename.substring(0,filename.lastIndexOf("."));
       String endung="";
       try{
        endung = "."+((MagicFormatParser)this.mv.getParserComboBox().getSelectedItem()).getFileType();
       }catch(NullPointerException e){System.out.println(e.getMessage());}
       return name+endung;
    }

    @Override
    public Object convertReverse(Object value) {
       String filename = (String) value;
       if(!filename.contains("."))return filename;
       String name = filename.substring(0,filename.lastIndexOf("."));
       String endung="";
       try{
           endung =  "."+this.mv.getInputFileType();
       }catch(NullPointerException e){}
       return name+endung;
    }
    
}
